// ================================================================================
// 		File: PatyEduSubjectOptions.cs
// 		Desc: 
//  
// 		Called by:   
//               
// 		Auth: chenwenzhi（--）
// 		Date: 2015-12-27 22:18
// ================================================================================
// 		Change History
// ================================================================================
// 		Date:		Author:				Description:
// 		--------	--------			-------------------
//    
// ================================================================================
// ================================================================================
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace ZHDJ.Data.Models.Edu
{
    /// <summary>
    /// 题目选项
    /// </summary>   
    public class PartyEduSubjectOptions : EntityBaseOperation
    {
        #region 属性

        /// <summary>
        /// 题目ID
        /// </summary>
        public string SubjectID { get; set; }

        /// <summary>
        /// 选项内容
        /// </summary>
        [Required, StringLength(256)]
        public string OptionsContent { get; set; }

        /// <summary>
        /// 是否选中答案
        /// </summary>
        public bool IsAnswer { get; set; }

        /// <summary>
        /// OrderNo
        /// </summary>
        public int OrderNo { get; set; }

        public virtual PartyEduSubject PatyEduSubject { get; set; }
        #endregion

        #region 数据查询
        /// <summary>
        /// 获取测试题
        /// </summary>
        /// <param name="top">几条</param>
        /// <param name="loginID">测试人</param>
        /// <returns></returns>
        public static DataSet GetPartyEduSubjectOptions(string subjectID)
        {
            string sql = @" select ID,OrderNo,OptionsContent,IsAnswer,SubjectID from tblPartyEduSubjectOptions where SubjectID=?SubjectID";
            MySqlParameter[] para = new MySqlParameter[] {
                new MySqlParameter() {
                DbType =DbType.String, ParameterName= "SubjectID",Value= subjectID }
            };
            return MySqlHelper.ExecuteDataSet(sql, para);
        }

        /// <summary>
        /// 获取测试题
        /// </summary>
        /// <param name="top">几条</param>
        /// <param name="loginID">测试人</param>
        /// <returns></returns>
        public static DataSet GetPartyEduSubjectOptions(string[] subjectIDs)
        {
            if (subjectIDs == null)
            {
                subjectIDs[0] = "";
            }
            var paraStr = "";
            int index = 0;
            MySqlParameter[] para = new MySqlParameter[subjectIDs.Count()];
            foreach (var item in subjectIDs)
            {
                paraStr += "?SubjectID" + index + ",";
                para[index] = new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "SubjectID" + index,
                    Value = item
                };

                index += index;
            }
            paraStr.Trim(',');
            string sql = @" select ID,OrderNo,OptionsContent,IsAnswer,SubjectID from tblPartyEduSubjectOptions where 
            SubjectID in( " +
            paraStr
            + "@)";
            return MySqlHelper.ExecuteDataSet(sql, para);
        }
        #endregion
    }
}
